package com.aaa.system.controller.api;

import com.aaa.entity.Notice;
import com.aaa.system.aop.annotation.Log;
import com.aaa.system.service.INoticeService;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 响应到前端的controller类
 */
@RestController
@RequestMapping("system/api/notice")
public class ApiNoticeController {

    @Autowired
    private INoticeService noticeService;

    /**
     * 分页动态查询所有通知公告
     * @param current  当前页码
     * @param size  每页显示条数
     * @param notice 通知公告查询条件对象
     * @return
     */
    @PostMapping("selectAll/{current}/{size}")
    public Result<IPage<Notice>> selectAll(
            @PathVariable Integer current,
            @PathVariable Integer size,
            @RequestBody Notice notice
    ){
        Result<IPage<Notice>> selectAll = noticeService.selectAll(current,size,notice);
        return selectAll;
    }

    /**
     * 添加或者修改通知公告信息
     * @param notice 通知公告实体类
     * @return 字符串
     */
    @Log(title = "添加/修改通知公告信息",business_type = "1")
    @PostMapping("saveOrUpdateNotice")
    public Result<Boolean> saveOrUpdateNotice(@RequestBody Notice notice){
        return noticeService.saveOrUpdateNotice(notice);
    }

    /**
     * 根据通知公告id删除单条或多条通知公告
     * @param noticeIds 通知公告id数组
     * @return 操作结果信息
     */
    @Log(title = "删除通知公告",business_type = "3")
    @DeleteMapping("deleteNoticeByIds/{noticeIds}")
    public Result<Boolean> deleteNoticeByIds(@PathVariable Long[] noticeIds){
        return noticeService.deleteNoticeByIds(noticeIds);
    }
}
